/* 
 *api：所有与获取数据相关的api均可写在此文档中，注意添加注释，便于区分和定位
 *get，post均已封装，注意调用格式
 */
let app = getApp()
let config = require("../../config.js")
let {
  get,
  post,
  upload
} = require("./request.js")

const api_QueryTopicRefresh = (params, callback) => {
  let url = '/topic/queryTopicRefresh'
  get(url, (res) => {
    callback(res.data)
  })
}

const api_GetTopicByUserid = (data, callback) => {
  let url = '/topic/queryTopicById'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_GetTopicByTopicid = (data, callback) => {
  let url = '/topic/queryTopicByTopicid'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_GetTopicAnswer = (data,callback) => {
  let url = '/topic/queryTopicAnswer?topicid='+data
  get(url,(res) => {
    callback(res)
  })
}

const api_GetUserAnswer = (data, callback) => {
  let url = '/topic/queryUserAnswer'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_GetAnswerUser = (data, callback) => {
  let url = '/topic/queryAnswerUser'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_AddTopic = (data, callback) => {
  let url = '/topic/addTopic'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_AddTopicFavourate = (data, callback) => {
  let url = '/topic/addTopicFavourate'
  post(url,data, (res) => {
    callback(res)
  })
}

const api_SubTopicFavourate = (data, callback) => {
  let url = '/topic/subTopicFavourate'
  post(url, data, (res) => {
    callback(res)
  })
}


const api_MakeComment = (data, callback) => {
  let url = '/topic/addTopicComment'
  post(url,data, (res) => {
    callback(res)
  })
}

const api_MakeAnswer = (data, callback) => {
  let url = '/topic/addTopicAnswer'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_GetGoods = (callback) => {
  let url = '/exchange/queryGoods'
  get(url, (res) => {
    callback(res)
  })
}

const api_GetExchangeInfo = (data,callback) => {
  let url = '/exchange/queryExchagneInfo'
  post(url,data, (res) => {
    callback(res)
  })
}

const api_GetUserYisen = (data,callback) => {
  let url = '/exchange/queryYisen'
  post(url,data, (res) => {
    callback(res)
  })
}

const api_MakeOrder = (data, callback) => {
  let url = '/exchange/addOrder'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_ExchangeYisen = (data, callback) => {
  let url = '/exchange/exchangeYisen'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_QueryExchangeRecord = (data, callback) => {
  let url = '/exchange/queryExchangeRecordByUserid'
  post(url, data, (res) => {
    callback(res)
  })
}

const api_addUserAddr = (data, callback) => {
  let url = '/exchange/addUserAddr'
  post(url, data, (res) => {
    callback(res)
  })
}



/**************************************用户信息相关API**********************************************/

/* 获取用户权限 */
const api_GetAllAuthorities = (callback) => {
  if (app.allAuthorities) {
    callback(app.allAuthorities)
  } else {
    get('/buaa/uc/getAllAuthorities', (res) => {
      app.allAuthorities = res.data
      callback(app.allAuthorities)
    })
  }
};



/*通过token获取用户信息 */
const api_uc_GetInfoByToken = (callback) => {
  let url = '/buaa/uc/getUserInfoByToken'
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 获取账户状态
 * @returns {*}
 */
const api_GetUserState = (callback) => {
  let url = '/buaa/act/getUserState'
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 获取积分变更记录
 * @param page
 * @param size
 * @returns {*}
 */
const api_GetPointChangeRecords = (params, callback) => {
  let url = '/buaa/act/getPointChangeRecords' + '?page=' + params.page + '&size=' + params.page
  get(url, (res) => {
    callback(res.data)
  })
}

/**
 * 获取信用分变更记录
 * @param page
 * @param size
 * @returns {*}
 */
const api_GetCreditChangeRecords = (params, callback) => {
  let url = '/buaa/act/getCreditChangeRecords' + '?page=' + params.page + '&size=' + params.page
  get(url, (res) => {
    callback(res.data)
  })
}



/**************************************首页微沙龙相关API**********************************************/
/* 获取主页活动列表@暂存到全局变量中，刷新时更新 */
const api_GetActList = (params, callback) => {
  let url = '/topic/queryTopicAll'
  get(url, (res) => {
    callback(res.data)
  })
}

/**
 * 更改喜欢状态
 * @param actId
 * @returns {*}
 */
const api_LikeAct = (param, callback) => {
  let url = '/buaa/act/toggleFavorite'
  post(url, param, (res) => {
    callback(res)
  })
}
/**************************************活动搜索相关API**********************************************/
/**
 * 活动搜索
 * @param keywords
 * @param searchType
 * @param page
 * @param size
 * @returns {*}
 */
const api_SearchAct = (params, callback) => {
  let url = '/buaa/act/searchAct' + '?keywords=' + params.keywords + '&searchType=' + params.searchType + '&page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res.data)
  })
}


/**************************************学术活动相关API**********************************************/
/* 学术主页活动列表 */
const api_GetAcadActListOn = (params, callback) => {
  let url = '/buaa/act/getActList' + '?page=' + params.page + '&size=' + params.size + '&actListType=2&state=1'
  get(url, (res) => {
    callback(res.data)
  })
}
/* 获取学术主页活动列表 */
const api_GetAcadActListOff = (params, callback) => {
  let url = '/buaa/act/getActList' + '?page=' + params.page + '&size=' + params.size + '&actListType=2&state=0'
  get(url, (res) => {
    callback(res.data)
  })
}

/* 获取活动详情 */
const api_GetActivityInfo = (params, callback) => {
  let url = '/buaa/act/getActivityInfo' + '?actId=' + params
  get(url, (res) => {
    // app.discoverList = res.data
    callback(res)
  })
}


/**************************************发起活动相关API**********************************************/
/**
 * 获取发起活动表单
 */
const api_GetActApplyForm = (callback) => {
  let url = '/buaa/act/getActApplyForm'
  get(url, (res) => {
    callback(res)
  })
}
/**
 * 发起新活动
 */
const api_ApplyNewAct = (form, callback) => {
  let url = '/buaa/act/applyNewAct'
  //console.log(form.get('type'))
  post(url, form, (res) => {
    callback(res)
  })
}


/**************************************活动审核相关API**********************************************/
/**
 * 获取未审核活动列表
 * @param page
 * @param size
 */
const api_GetActivitiesToAudit = (params, callback) => {
  let url = '/buaa/act/getActivitiesToAudit' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 获取已审核活动列表
 * @param page
 * @param size
 */
const api_GetActivitiesAudited = (params, callback) => {
  let url = '/buaa/act/getActivitiesAudited' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 获取未审核活动详情
 * @param actApplyFormId
 */
const api_GetApplyFormDetail = (params, callback) => {
  let url = '/buaa/act/getActApplyFormDetail?actApplyFormId=' + params
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 提交用户审核结果（审核通过）
 * @param result
 */
const api_DealPassAudit = (result, callback) => {
  let url = '/buaa/act/dealPassAudit'
  post(url, result, (res) => {
    callback(res)
  })
}

/**
 * 提交用户审核结果（审核不通过）
 * @param result
 */
const api_DealRejectAudit = (result, callback) => {
  let url = '/buaa/act/dealRejectAudit'
  post(url, result, (res) => {
    callback(res)
  })
}

/**************************************我的活动相关API**********************************************/
/**
 * 获取我报名的活动列表
 * @param page
 * @param size
 * @returns {*}
 */
const api_GetActivitiesSign = (params, callback) => {
  let url = '/buaa/act/getParticipatedActList' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 获取我发起的活动列表
 * @param page
 * @param size
 * @returns {*}
 */
const api_GetActivitiesApply = (params, callback) => {
  let url = '/buaa/act/getMyApply' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}

/**************************************活动签到相关API**********************************************/
/**
 * 获取可签到的活动列表
 * @returns {*}
 */
const api_GetConsumeActList = (callback) => {
  let url = '/buaa/act/getConsumeActList'
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 提交核验码
 * @param formData
 * @returns {*}
 */
// export function api_SignIn(formData) {
//   return http({
//     url: '/buaa/act/signIn',
//     method: 'post',
//     data: formData
//   })
// }

/**
 * 获取参与人列表
 * @param actId
 * @param page
 * @param size
 * @returns {*}
 */
const api_GetParticipatedList = (params, callback) => {
  let url = '/buaa/act/getParticipatedUserList' + '?actId=' + params.actId + '&page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}


/**************************************发现相关API**********************************************/
/* 获取发现列表 */
const api_GetDiscoverList = (params, callback) => {
  //if (app.discoverList){
  //  callback(app.discoverList)
  //}else{
  let url = '/buaa/act/get_find_content_list' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    app.discoverList = res.data
    callback(app.discoverList)
  })
}

/*新增发现 */
const api_AddDiscover = (form, callback) => {
  let url = '/buaa/act/add_find_content'
  //console.log(form.get('type'))
  post(url, form, (res) => {
    callback(res)
  })
}
/* 删除发现*/
const api_RemoveDiscover = (form, callback) => {
  let url = '/buaa/act/remove_find_content'
  post(url, form, (res) => {
    callback(res)
  })
}

/**************************************用户审核相关API**********************************************/
/**
 * 获取已审核用户表单
 * @param page
 * @param size
 */
const api_GetAuditDoneList = (params, callback) => {
  let url = '/buaa/uc/getUsersAudited' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}
/**
 * 获取未审核用户表单
 * @param page
 * @param size
 */
const api_GetAuditTODOList = (params, callback) => {
  let url = '/buaa/uc/getUsersToAudit' + '?page=' + params.page + '&size=' + params.size
  get(url, (res) => {
    callback(res)
  })
}

/**
 * 获取审核列表用户详情
 * @param applyId
 * 
 */
const api_GetRegisterFormById = (params, callback) => {
  let url = '/buaa/uc/getRegisterFormById?applyId=' + params
  get(url, (res) => {
    callback(res)
  })
}

/**************************************轮播设置相关API**********************************************/
/* 获取轮播图 */
const api_GetAllBanners = (callback) => {
  // if (app.allBanners) {
  //   callback(app.allBanners)
  // } else {
  get('/buaa/act/getAllBanners', (res) => {
    // app.allBanners = res.data.data
    // callback(app.allBanners)
    callback(res.data.data)
    //console.log("1111",res.data.data)
  })
  // }
};

/* 删除轮播*/
const api_DeleteBanner = (bannerId, callback) => {
  let url = '/buaa/act/removeBanner'
  var params = {
    'bannerId': bannerId
  }
  post(url, params, (res) => {
    callback(res)
  })
}

/*增加轮播 */
const api_AddBanner = (form, imgPath, callback) => {
  let url = '/buaa/act/addBanner'
  upload(url, form, imgPath, (res) => {
    callback(res)
  })
}

/*发送反馈 */
const api_AddFeed = (form, callback) => {
  let url = '/buaa/act/add_feed'
  post(url, form, (res) => {
    callback(res)
  })
}

/*************************************发送模板消息**********************************************/
const api_SendTemplateMessage = (form, callback) => {
  let url = '/buaa/act/sendTemplateMessage'
  post(url, form, (res) => {
    callback(res)
  })
}

/*************************************获取用户真实信息**********************************************/
const api_GetRealUserInfo = (param, callback) => {
  let url = '/buaa/autho/wx_app_real_auth'
  post(url, param, (res) => {
    callback(res)
  })
}

/*************************************取消活动**********************************************/
/**
 * 取消活动
 * @param form
 * @returns {*}
 */
const api_DeleteActivity = (param, callback) => {
  let url = '/buaa/act/cancelActivity'
  post(url, param, (res) => {
    callback(res)
  })
}

//注意每个函数都要在此声明，为了便于与普通函数区分，推荐使用前缀 api_
module.exports = {
  api_GetAllBanners: api_GetAllBanners,
  api_GetAllAuthorities: api_GetAllAuthorities,
  api_GetActList: api_GetActList,
  api_GetAcadActListOn: api_GetAcadActListOn,
  api_GetAcadActListOff: api_GetAcadActListOff,
  api_GetActivityInfo: api_GetActivityInfo,
  api_GetDiscoverList: api_GetDiscoverList,
  api_GetActivitiesSign: api_GetActivitiesSign,
  api_GetActivitiesApply: api_GetActivitiesApply,
  api_GetActivitiesToAudit: api_GetActivitiesToAudit,
  api_GetActivitiesAudited: api_GetActivitiesAudited,
  api_AddDiscover: api_AddDiscover,
  api_RemoveDiscover: api_RemoveDiscover,
  api_GetActApplyForm: api_GetActApplyForm,
  api_ApplyNewAct: api_ApplyNewAct,
  api_AddBanner: api_AddBanner,
  api_DeleteBanner: api_DeleteBanner,
  api_uc_GetInfoByToken: api_uc_GetInfoByToken,
  api_GetApplyFormDetail: api_GetApplyFormDetail,
  api_DealPassAudit: api_DealPassAudit,
  api_DealRejectAudit: api_DealRejectAudit,
  api_GetConsumeActList: api_GetConsumeActList,
  api_LikeAct: api_LikeAct,
  api_GetAuditDoneList: api_GetAuditDoneList,
  api_GetAuditTODOList: api_GetAuditTODOList,
  api_SearchAct: api_SearchAct,
  api_GetRegisterFormById: api_GetRegisterFormById,
  api_GetParticipatedList: api_GetParticipatedList,
  api_GetUserState: api_GetUserState,
  api_GetPointChangeRecords: api_GetPointChangeRecords,
  api_GetCreditChangeRecords: api_GetCreditChangeRecords,
  api_AddFeed: api_AddFeed,
  api_SendTemplateMessage: api_SendTemplateMessage,
  api_GetRealUserInfo: api_GetRealUserInfo,
  api_DeleteActivity: api_DeleteActivity,
  api_GetTopicAnswer: api_GetTopicAnswer,
  api_MakeComment: api_MakeComment,
  api_MakeAnswer: api_MakeAnswer,
  api_GetGoods: api_GetGoods,
  api_GetUserYisen: api_GetUserYisen,
  api_GetExchangeInfo: api_GetExchangeInfo,
  api_MakeOrder: api_MakeOrder,
  api_AddTopicFavourate: api_AddTopicFavourate,
  api_GetTopicByUserid: api_GetTopicByUserid,
  api_GetUserAnswer: api_GetUserAnswer, 
  api_GetAnswerUser: api_GetAnswerUser,
  api_ExchangeYisen: api_ExchangeYisen,
  api_QueryExchangeRecord: api_QueryExchangeRecord,
  api_AddTopic: api_AddTopic,
  api_QueryTopicRefresh: api_QueryTopicRefresh,
  api_SubTopicFavourate: api_SubTopicFavourate,
  api_GetTopicByTopicid: api_GetTopicByTopicid,
  api_addUserAddr: api_addUserAddr
}